package com.hsmpay.mobile.dao.brokerage.impl;

import com.hsmpay.common.dao.Impl.BaseDaoSupport;
import com.hsmpay.mobile.dao.brokerage.BrokEachOrderDao;
import com.hsmpay.mobile.pojo.brokerage.BrokEachOrder;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 合作银行 Dao接口实现类
 *
 * @author 颜铃璋
 *         建立时间：2012-12-13
 */
@Repository("brokEachOrderDao")
public class BrokEachOrderDaoImpl extends BaseDaoSupport<BrokEachOrder, Long> implements BrokEachOrderDao<BrokEachOrder, Long> {
    /**
     * 调用存储过程 计算佣金
     *
     * @param roleId
     * @param roleType
     * @param orgId
     * @param transMoney
     * @param fee
     * @param feeRate
     * @param orderNum
     * @param clientType
     * @param orderDate
     * @param revenueFee
     * @param userId
     * @return
     * @throws SQLException
     */
    @SuppressWarnings("unused")
    public int proBrokMobile(Long roleId, Integer roleType, Long orgId, Double transMoney, Double fee, Double feeRate, String orderNum, Integer clientType, Date orderDate, Double revenueFee, Long userId) throws SQLException {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("roleId", roleId);
        param.put("roleType", roleType);
        param.put("orgId", orgId);
        param.put("transMoney", transMoney);
        param.put("fee", fee);
        param.put("feeRate", feeRate);
        param.put("orderNum", orderNum);
        param.put("clientType", clientType);
        param.put("orderDate", orderDate);
        param.put("longcdate", orderDate.getTime());
        param.put("revenueFee", revenueFee);
        param.put("userId", userId);

        Integer flag = (Integer) getSqlMapClientTemplate().queryForObject("brokEachOrderSqlMap.proBrokMobile", param);
//		log.debug(" flag = "+flag);
//		log.debug(" status = "+param.get("status"));
        return 1;
    }

    /**
     * 删除订单
     *
     * @param orderNum
     * @return
     * @throws SQLException
     */
    public int deleteBrokEachOrderByOrderNum(String orderNum) throws SQLException {
        return getSqlMapClientTemplate().delete("brokEachOrderSqlMap.deleteBrokEachOrderByOrderNum", orderNum);
    }

    /**
     * 分组查询 机构 所得佣金(总的)
     * @param param
     * @return
     * @throws SQLException
     */
    @SuppressWarnings("unchecked")
    public List<BrokEachOrder> searchEachOGBOrgIdList(Map<String, Object> param) throws SQLException {
        return getSqlMapClientTemplate().queryForList("brokEachOrderSqlMap.searchEachOGBOrgIdList",param);
    }

    /**
     * 分组查询 机构 所得佣金
     * @param param
     * @return
     * @throws SQLException
     */
    @SuppressWarnings("unchecked")
    public List<BrokEachOrder> searchEachOGBOrgIdRoleIdList(Map<String,Object> param)throws SQLException{
        return getSqlMapClientTemplate().queryForList("brokEachOrderSqlMap.searchEachOGBOrgIdRoleIdList",param);
    }

    /**
     * 更新生成了结算订单的佣金订单
     * @param param
     * @return
     * @throws SQLException
     */
    @SuppressWarnings("unchecked")
    public Integer updateBrokEachOrderClearStatusByOrg(Map<String,Object> param)throws SQLException{
        return getSqlMapClientTemplate().update("brokEachOrderSqlMap.updateBrokEachOrderClearStatusByOrg",param);
    }

    /**
     * 查询生成佣金结算订单的收款订单的时间范围
     * @param param
     * @return
     * @throws SQLException
     */
    @SuppressWarnings("unchecked")
    public BrokEachOrder minAndMaxCreatDateInTransOrder(Map<String,Object> param)throws SQLException{
        return (BrokEachOrder)getSqlMapClientTemplate().queryForObject("brokEachOrderSqlMap.minAndMaxCreatDateInTransOrder",param);
    }

    /**
     * 根据id更新BrokEachOrder状态
     * @param brokEachOrder
     * @return
     * @throws SQLException
     */
    @SuppressWarnings("unchecked")
    public Integer updateClearStatusById(BrokEachOrder brokEachOrder)throws SQLException{
        return getSqlMapClientTemplate().update("brokEachOrderSqlMap.updateClearStatusById",brokEachOrder);
    }
}
